package com.hodgepodge.commons.entity;

import com.baomidou.mybatisplus.annotation.TableId;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.hodgepodge.commons.constant.Regexp;
import com.hodgepodge.commons.base.entity.SuperEntity;
import com.hodgepodge.commons.validator.annotation.FixedNumValues;
import com.hodgepodge.commons.validator.group.Insert;
import com.hodgepodge.commons.validator.group.Update;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.hibernate.validator.constraints.Length;
import org.springframework.format.annotation.DateTimeFormat;

import javax.validation.constraints.Email;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
import java.util.Date;

/**
 * <p>
 * 用户表
 * </p>
 *
 * @author jiangjian
 * @since 2021-02-02
 */
@Data
@EqualsAndHashCode(callSuper = false)
@ApiModel(description = "标签")
public class User extends SuperEntity<User> {

    private static final long serialVersionUID = 6619667644330972745L;

    /**
     * 用户ID
     */
    @ApiModelProperty(value = "用户ID")
    @NotNull(message = "用户ID不能为空", groups = Update.class)
    @TableId("user_id")
    private Long userId;

    /**
     * 用户名
     */
    @ApiModelProperty(value = "用户名")
    @NotBlank(message = "用户名不能为空", groups = Insert.class)
    @Length(max = 20, message = "用户名不能超过20个字符", groups = {Insert.class, Update.class})
    private String username;

    /**
     * 密码
     */
    @ApiModelProperty(value = "密码")
    @NotBlank(message = "用户名不能为空", groups = Insert.class)
    @Length(min = 8, max = 20, message = "密码8-20个字符", groups = {Insert.class, Update.class})
    private String password;

    /**
     * 性别(1:男 2:女 0:未知)
     */
    @ApiModelProperty(value = "性别(1:男 2:女 0:未知)")
    @FixedNumValues(values = {0, 1, 2}, message = "性别只能是(1:男 2:女 0:未知)", groups = {Insert.class, Update.class})
    private Integer gender;

    /**
     * 年龄
     */
    @ApiModelProperty(value = "年龄")
    private Integer age;

    /**
     * 生日
     */
    @ApiModelProperty(value = "生日")
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    @JsonFormat(pattern = "yyyy-MM-dd")
    private Date birthday;

    /**
     * 手机号
     */
    @ApiModelProperty(value = "手机号")
    @Pattern(regexp = Regexp.TEL, message = "手机号格式有误", groups = {Insert.class, Update.class})
    private String tel;

    /**
     * 邮箱
     */
    @ApiModelProperty(value = "邮箱")
    @Email(regexp = Regexp.EMAIL, message = "邮箱格式有误", groups = {Insert.class, Update.class})
    private String email;

    /**
     * 最近登录IP
     */
    @ApiModelProperty(value = "最近登录IP")
    private String ip;

    /**
     * 头像
     */
    @ApiModelProperty(value = "头像")
    private String avatar;

    /**
     * 用户状态(0:正常 1:禁用)
     */
    @ApiModelProperty(value = "用户状态(0:正常 1:禁用)")
    @FixedNumValues(values = {0, 1}, message = "用户状态只能是(0:正常 1:禁用)", groups = {Insert.class, Update.class})
    private Integer state;

}
